<%@page import="java.util.Map"%>
<%@page import="com.situ.personal.entity.User"%>
<%@page import="java.util.List"%>
<%@page import="com.situ.personal.entity.PageInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<%-- <a class="btn btn-primary" href="<%=request.getContextPath()%>/user_insert.jsp">添加</a> --%>
	<!-- 原来是直接通过超链接直接请求后台页面，现在是先请求后台UserServlet，查出所有List<Department> list,
	再转法到user_insert.jsp -->
	<a class="btn btn-primary" href="<%=request.getContextPath()%>/user?method=getUserInsertPage">添加</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<th>ID</th>
			<th>名字</th>
			<th>年龄</th>
			<th>密码</th>
			<th>邮箱</th>
			<th>部门ID</th>
			<th>删除</th>
			<th>修改</th>
		</tr>
		<%
			PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
			List<Map<String, Object>> list = pageInfo.getList();
			for (Map<String, Object> map : list) {
		%>
				<tr>
					<td><%=map.get("id")%></td>
					<td><%=map.get("name")%></td>
					<td><%=map.get("age")%></td>
					<td><%=map.get("password")%></td>
					<td><%=map.get("email")%></td>
					<td><%=map.get("deptName")%></td>
					<td><a href="javascript:void(0)" onclick="deleteById(<%=map.get("id")%>)">删除</a></td>
					<td><a href="<%=request.getContextPath()%>/user?method=selectById&id=<%=map.get("id")%>">修改</a></td>
				</tr>
		<%
		    }
		%>
		<c:forEach items="${pageInfo.list}" var="map">
			<tr>
				<td>${map["id"]}</td>
				<td>${map['name']}</td>
				<td>${map['age']}</td>
				<td>${map['password']}</td>
				<td>${map['email']}</td>
				<td>${map['deptName']}</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${map['id']})">删除</a></td>
				<td><a href="${pageContext.request.contextPath}/user?method=selectById&id=${map['id']}">修改</a></td>
				</tr>
		</c:forEach>
				
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  <% 
	  if(pageInfo.getPageNo() == 1){
	  %>
	     <li class = "disabled">
	  
	      <a href="#" aria-label="Previous">
	        <span aria-hidden="true">&laquo;</span>
	      </a>
	     </li>
	    <%
	    }
	    else{
	    %>
	     <li>
	  
	      <a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=pageInfo.getPageNo() - 1%>" aria-label="Previous">
	        <span aria-hidden="true">&laquo;</span>
	      </a>
	     </li>
	     <%
	     }
	     %>
	     <%
	    	int totalPage = pageInfo.getTotalPage();
	        int pageNo = pageInfo.getPageNo();
	    	for(int i = 1; i<= totalPage; i++) {
	    		if(pageNo == i){
	     %>
	    			<li  class = "active"><a  href=""><%=i%></a></li>
	     <%
	    		
	    		}else{
	    %>
	    			<li><a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=i%>"><%=i%></a></li>
	    <% 			
	    		}
	  
	    		
	    	}
	    %>
	     <% 
	  if(pageInfo.getPageNo() == pageInfo.getTotalPage()){
	  %>
	     <li class = "disabled">
	  
	      <a href="#" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	     </li>
	    <%
	    }
	    else{
	    %>
	     <li>
	  
	      <a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=pageInfo.getPageNo() + 1%>" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	     </li>
	     <%
	     }
	     %>
	  </ul>
	</nav>

	<script type="text/javascript">
		function deleteById(id) {
			var isDel = confirm("您确认要删除么？");
			if (isDel) {
				location.href = "/Java1912WebPersonal/user?method=deleteById&id=" + id;
			}
		}
	</script>
</body>
</html>